<script setup lang="ts">
import lodash from 'lodash'
import {getStudy,saveStudy} from '@/api/study'
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const props = defineProps(['id'])
const emits = defineEmits(['close'])
const loading = ref<boolean>(false)
const show = ref<boolean>(false)
const dataForm = ref<any>({
    id:undefined,
    name:undefined,
    device:undefined,
    gender:1,
    age:undefined,
    date:undefined,
    report_time:undefined,
    status:undefined,
    printnum:undefined
})

const domForm = ref()

const descPosiOptions = ['左', '右', '正位', '斜位', '双斜位', '侧位', '正侧位', '双侧位', '前后位', '后前位', '轴位', '双'];

const descElseOptions = ['+', ';', '部', '(职业病)'];

const descOptions = ['头', '颈椎', '肩关节', '肩胛骨', '胸', '肘关节', '腕关节', '手', '腰椎', '胫腓骨', '骨盆', '髋关节', '跟骨', '双跟骨轴位', '膝关节', '踝关节', '足', '股骨', '腹部'];

const handleSave = () => {
    domForm.value.validate((valid:boolean)=>{
        if(!valid)return
		loading.value = true
		saveStudy(lodash.cloneDeep(dataForm.value)).then(()=>{
			proxy?.$modal.alertSuccess('保存成功')
			loading.value = false
            handleClose(true)
		})
    })
}

const handleQuickPick = (item: string) => {
	dataForm.value.locate += item
}

const handleClose = (refresh?:boolean) => {
    emits('close',{refresh})
}

onMounted(()=>{
	getStudy(props.id).then((e:any)=>{
		const {row} = e
		dataForm.value = row
	})
})

show.value = true
</script>

<template>
	<el-dialog v-model="show" title="修改信息" width="800" :close-on-click-modal="false" :show-close="false">
		<el-form ref="domForm" :model="dataForm" label-width="auto" v-loading="loading">
			<el-row :gutter="20">
				<el-col :span="12">
					<el-form-item label="姓名" prop="name" required>
						<el-input v-model="dataForm.name" placeholder="请输入影响所属人姓名" />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="检查设备">
						<el-select v-model="dataForm.device">
							<el-option label="CT" value="ct" />
							<el-option label="MR" value="mr" />
							<el-option label="DX" value="dx" />
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="12">
					<el-form-item label="性别">
						<el-radio-group v-model="dataForm.gender">
							<el-radio :label="1">男</el-radio>
							<el-radio :label="0">女</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="年龄" prop="age">
						<el-input v-model="dataForm.age" type="number" placeholder="请输入影响所属人年龄" />
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="12">
					<el-form-item label="影像时间" prop="date" required>
						<el-date-picker v-model="dataForm.date" type="date" value-format="YYYY-MM-DD" placeholder="请选择影像时间" style="width:80%" />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="报告时间" prop="report_time">
						<el-date-picker v-model="dataForm.report_time" type="date" value-format="YYYY-MM-DD" placeholder="请选择报告时间" style="width:80%" />
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="20">
				<el-col :span="12">
					<el-form-item label="报告状态">
						<el-radio-group v-model="dataForm.status">
							<el-radio :label="1">已编辑</el-radio>
							<el-radio :label="0">未编写</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="打印次数" prop="printnum">
						<el-input v-model="dataForm.printnum" type="number" placeholder="请输入打印次数" />
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="检查部位" prop="locate" required>
				<el-input v-model="dataForm.locate" placeholder="请输入检查部位" clearable />
			</el-form-item>
			<el-form-item class="mine">
				<el-tag v-for="item in descOptions" :key="item" size="large" class="jcbw-tag mg-bottom" @click="handleQuickPick(item)">{{ item }}</el-tag>
			</el-form-item>
			<el-form-item class="mine">
				<el-tag v-for="item in descPosiOptions" :key="item" size="large" class="jcbw-tag" type="success" @click="handleQuickPick(item)">{{ item
				}}</el-tag>
			</el-form-item>
			<el-form-item>
				<el-tag v-for="item in descElseOptions" :key="item" size="large" class="jcbw-tag" type="danger" @click="handleQuickPick(item)">{{ item
				}}</el-tag>
			</el-form-item>
		</el-form>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="handleClose">取消</el-button>
				<el-button type="primary" @click="handleSave" :loading="loading"> 确认修改 </el-button>
			</div>
		</template>
	</el-dialog>
</template>
<style lang="scss"></style>
<style lang="scss" scoped>

.jcbw-tag {
	cursor: pointer;
	margin-right: 5px;
	margin-bottom: 5px;
}
</style>
